<template>
  <div class="config-view">
    <a-card class="config-card" title="系统配置">
      <a-tabs>
        <a-tab-pane key="1" title="基础设置">
          <a-form :model="basicConfig" layout="vertical">
            <a-form-item field="systemName" label="系统名称">
              <a-input
                v-model="basicConfig.systemName"
                placeholder="请输入系统名称"
              />
            </a-form-item>
            <a-form-item field="systemLogo" label="系统Logo">
              <a-upload
                action="/api/file/upload"
                :file-list="fileList"
                list-type="picture-card"
                :limit="1"
              >
                <template #upload-button>
                  <div>
                    <icon-plus />
                    <div>上传Logo</div>
                  </div>
                </template>
              </a-upload>
            </a-form-item>
            <a-form-item field="adminEmail" label="管理员邮箱">
              <a-input
                v-model="basicConfig.adminEmail"
                placeholder="请输入管理员邮箱"
              />
            </a-form-item>
            <a-form-item field="copyrightInfo" label="版权信息">
              <a-input
                v-model="basicConfig.copyrightInfo"
                placeholder="请输入版权信息"
              />
            </a-form-item>
            <a-form-item>
              <a-button type="primary" @click="saveBasicConfig"
                >保存配置</a-button
              >
            </a-form-item>
          </a-form>
        </a-tab-pane>

        <a-tab-pane key="2" title="判题设置">
          <a-form :model="judgeConfig" layout="vertical">
            <a-form-item field="timeLimit" label="默认时间限制(ms)">
              <a-input-number
                v-model="judgeConfig.timeLimit"
                placeholder="请输入时间限制"
                :min="100"
                :max="60000"
              />
            </a-form-item>
            <a-form-item field="memoryLimit" label="默认内存限制(MB)">
              <a-input-number
                v-model="judgeConfig.memoryLimit"
                placeholder="请输入内存限制"
                :min="16"
                :max="1024"
              />
            </a-form-item>
            <a-form-item field="stackLimit" label="默认栈限制(MB)">
              <a-input-number
                v-model="judgeConfig.stackLimit"
                placeholder="请输入栈限制"
                :min="1"
                :max="1024"
              />
            </a-form-item>
            <a-form-item field="maxCodeLength" label="最大代码长度(字节)">
              <a-input-number
                v-model="judgeConfig.maxCodeLength"
                placeholder="请输入最大代码长度"
                :min="1024"
                :max="1048576"
              />
            </a-form-item>
            <a-form-item>
              <a-button type="primary" @click="saveJudgeConfig"
                >保存配置</a-button
              >
            </a-form-item>
          </a-form>
        </a-tab-pane>

        <a-tab-pane key="3" title="安全设置">
          <a-form :model="securityConfig" layout="vertical">
            <a-form-item field="loginAttempts" label="最大登录尝试次数">
              <a-input-number
                v-model="securityConfig.loginAttempts"
                placeholder="请输入最大登录尝试次数"
                :min="1"
                :max="20"
              />
            </a-form-item>
            <a-form-item field="lockTime" label="账户锁定时间(分钟)">
              <a-input-number
                v-model="securityConfig.lockTime"
                placeholder="请输入账户锁定时间"
                :min="1"
                :max="1440"
              />
            </a-form-item>
            <a-form-item field="passwordExpiration" label="密码过期时间(天)">
              <a-input-number
                v-model="securityConfig.passwordExpiration"
                placeholder="请输入密码过期时间"
                :min="0"
                :max="365"
              />
              <template #help>设置为0表示永不过期</template>
            </a-form-item>
            <a-form-item field="passwordComplexity" label="密码复杂度要求">
              <a-checkbox-group v-model="securityConfig.passwordComplexity">
                <a-checkbox value="uppercase">必须包含大写字母</a-checkbox>
                <a-checkbox value="lowercase">必须包含小写字母</a-checkbox>
                <a-checkbox value="number">必须包含数字</a-checkbox>
                <a-checkbox value="special">必须包含特殊字符</a-checkbox>
              </a-checkbox-group>
            </a-form-item>
            <a-form-item>
              <a-button type="primary" @click="saveSecurityConfig"
                >保存配置</a-button
              >
            </a-form-item>
          </a-form>
        </a-tab-pane>
      </a-tabs>
    </a-card>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from "vue";
import { Message } from "@arco-design/web-vue";

const fileList = ref([]);

// 基础配置
const basicConfig = reactive({
  systemName: "黄海OJ在线判题系统",
  systemLogo: "",
  adminEmail: "admin@example.com",
  copyrightInfo: "Copyright © 2023-2024 黄海OJ",
});

// 判题配置
const judgeConfig = reactive({
  timeLimit: 1000,
  memoryLimit: 256,
  stackLimit: 128,
  maxCodeLength: 65536,
});

// 安全配置
const securityConfig = reactive({
  loginAttempts: 5,
  lockTime: 30,
  passwordExpiration: 0,
  passwordComplexity: ["lowercase", "number"],
});

// 保存基础配置
const saveBasicConfig = () => {
  // 这里应该调用后端API保存配置
  Message.success("基础配置保存成功");
};

// 保存判题配置
const saveJudgeConfig = () => {
  // 这里应该调用后端API保存配置
  Message.success("判题配置保存成功");
};

// 保存安全配置
const saveSecurityConfig = () => {
  // 这里应该调用后端API保存配置
  Message.success("安全配置保存成功");
};
</script>

<style scoped>
.config-view {
  padding: 0;
}

.config-card {
  margin-bottom: 16px;
}
</style>
